<?php

namespace app\admin\model;

use think\Model;

class Houseout extends Model
{
    // 表名
    protected $name = 'houseout';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'type_text',
        'inputtime_text'
    ];

    public function getOrderId(){

        $order_id = "OU-".date("Y")."TG-R-".date("md")."-".substr(time(),3).random(6,'0123456789');

        $info = $this->where(array('order_id' => $order_id))->find();

        if ($info) {
            $this->getOrderId();
        } else {
            return $order_id;
        }

    }


    public function getTypeList()
    {
        return ['1' =>"采购退货出库",'2' => "盘亏出库",'3' => "调拔出库",'4' => "要货出库",'5' => "销售出库",'6' => "其他出库",'7'=>'采购作废订单'];
    }     


    public function getTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['type'];
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getCidAttr($value){
        $db = new Githouse();
        $info = $db->where(array('id'=>$value))->field('gname')->find();
        return $info['gname'];
    }
    public function getShopidAttr($value){
        $db = new Preproduct();
        $info = $db->where(array('id'=>$value))->field('cname')->find();
        return $info['cname'];
    }




    public function getInputtimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['inputtime'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setInputtimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


}
